#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, r;
  cin >> n >> r;
  vector<int> digits;
  while(n) {
    digits.push_back(n % r);
    n /= r;
  }
  for (auto iter = digits.rbegin(); iter != digits.rend(); iter++) {
    if (*iter < 10) { 
      cout << *iter;
    } else {
      cout << char('A' + (*iter - 10));
    }
  }
  cout << endl;
  return 0;
}